<?php
namespace Admin\Controller;
use Think\Controller;
use think\Page;
class DucePriceController extends Controller{
    public function reduce(){
        $book_id=isset($_POST['book_id'])?trim($_POST['book_id']):null;
        $catId=isset($_POST['catId'])?trim($_POST['catId']):null;    //分类ID
        $count=isset($_POST['count'])?trim($_POST['count']):null;    //分类ID
        $IsShare=isset($_POST['IsShare'])?trim($_POST['IsShare']):1;    //是否分享
        if($catId==null||$count==null||$IsShare==nill){
            $requset=array('returnCode'=>999,'returnMsg'=>'请求数据不完整','returnData'=>null);
        }else{
            $postage=M('price')->where(['cate_id'=>$catId])->getField('postage');
            $re=M('book')->where(['id'=>$book_id])->field('price,minus')->find();
          if($postage==null||empty($re)){
              $requset=array('returnCode'=>999,'returnMsg'=>'空数据','returnData'=>null);
          }else{
              $totalmoney=$re['price']*$count;
              $minus=$IsShare?$re['minus']*$count:0;
              $totalprice=$totalmoney-$minus;
              $data['totalmoney']=$totalmoney;
              $data['minus']=$minus;
              $data['totalprice']=$totalprice;
              $data['postage']=$postage;
              $requset=array('returnCode'=>0,'returnMsg'=>'返回成功','returnData'=>$data);
              echo json_encode($requset); exit;
          }
        }
        
    }
    
}